const mongoose = require('mongoose')

const schema = new mongoose.Schema({
    name:{
        type:String
    },
    parent:{type:mongoose.Schema.Types.ObjectId,ref:'Category'}
})

// 子分类
schema.virtual('children',{
    localField:'_id',
    foreignField:'parent',
    justOne:false,
    ref:'Category'
}),

schema.virtual('newslist',{
    localField:'_id',
    foreignField:'categories',
    justOne:false,
    ref:'Article'
}),


module.exports = mongoose.model("Category",schema)